package com.system.outpatientsystem.controller;


import com.system.outpatientsystem.DTO.AppointmentDTO;
import com.system.outpatientsystem.pojo.Result;
import com.system.outpatientsystem.pojo.User;
import com.system.outpatientsystem.pojo.appointment_table;
import com.system.outpatientsystem.service.AppointService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/appointment")
public class AppointmentController {
    @Autowired
    private AppointService appointService;

    @PutMapping("/deleteAppointment")
    public Result deleteAppointment(@RequestBody Map<String,Integer> par){
        Integer id=par.get("id");
        System.out.println("deleteAppointmentId"+id);
        appointService.deleteAppointment(id);
        return Result.success("删除成功");
    }
    @PostMapping("/book")
    public Result appointment(@RequestBody appointment_table table){
        appointService.appointment(table);
        return Result.success("预约成功");
    }

    @PutMapping("/findById")
    public Result<AppointmentDTO> findById(@RequestBody Map<String,Integer> params){
        Integer id=params.get("id");
        AppointmentDTO appointmentDTO=appointService.findById(id);
        return Result.success(appointmentDTO);

    }
    @PutMapping("/findByUserId")
    public Result<List<AppointmentDTO>> findByUserId(@RequestBody Map<String,Integer> params){
//        Integer userId=user.getId();
         Integer userId=params.get("userId");
        List<AppointmentDTO> as=appointService.list(userId);
        return Result.success(as);
    }

    @PutMapping("/lessTwenty")
    public Result lessTwenty(@RequestBody Map<String,Integer> params){
        Integer id=params.get("id");
        if(!appointService.lessTwenty(id)){
            return Result.error("最多提前二十分钟");
        }
        return Result.success();

    }

}
